import {Injectable} from '@angular/core';

@Injectable()
export class ProductService {

  public products: Product[] = [
    new Product(1, 'iphonex', 8888.5, 3, '好好1', ['手机']),
    new Product(2, 'xiaomi', 7888.5, 5, '好好2', ['手机']),
    new Product(3, 'oppo', 6888.5, 4, '好好3', ['手机']),
    new Product(4, 'vivo', 5888.5, 1, '好好4', ['手机']),
    new Product(5, 'huawei', 3888.5, 3, '好好5', ['手机']),
    new Product(6, 'zte', 3888.5, 1, '好好6', ['手机'])
  ];

  constructor() {

  }

  getAllProducts() {
    return this.products;
  }

  getProduct(id: number): Product {

    return this.products.find((product) => product.id == id);
  }

}

/**
 * 定义产品的类
 **/
export class Product {

  constructor(public id: number,
              public title: string,
              public price: number,
              public rating: number,
              public desc: string,
              public categories: Array<string>) {

  }
}
